package com.transpot.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.transpot.entry.order.OrderStatus;
import com.transpot.service.order.OrderStatusService;
import com.transpot.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orderStatus")
public class OrderStatusController {
    @Autowired
    private OrderStatusService orderStatusService;

    /**
     * 修改订单状态方法
     * @param orderStatus
     * @return
     */
    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody OrderStatus orderStatus) {
        //创建订单状态条件查询对象
        LambdaQueryWrapper<OrderStatus> orderStatusLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //设置查询条件为与订单基本信息主键一致
        orderStatusLambdaQueryWrapper.eq(OrderStatus::getBaseId, orderStatus.getBaseId());
        //查询出订单状态对象
        OrderStatus status = orderStatusService.getOne(orderStatusLambdaQueryWrapper);
        //更改订单状态
        status.setStatus(orderStatus.getStatus());
        //更改数据库订单状态
        orderStatusService.updateById(status);
        //返回
        return R.success();
    }

    /**
     * 根据订单基本信息主键获得订单状态信息
     * @param id
     * @return
     */
    @GetMapping("/getOrderStatus")
    public R getOrderStatusById(Integer id) {
        //设置订单状态类条件查询对象
        LambdaQueryWrapper<OrderStatus> orderStatusLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //设置查询条件为与订单基本信息主键一致
        orderStatusLambdaQueryWrapper.eq(OrderStatus::getBaseId, id);
        //查询订单状态信息
        OrderStatus orderStatus = orderStatusService.getOne(orderStatusLambdaQueryWrapper);
        //返回
        return R.success(orderStatus);
    }
}
